<?php include '../public/header.php' ?>
<?php include '../public/header_index.php' ?>
<style>
    div[lay-id="datalist"] .layui-table-cell{
        height:auto !important;
    };
</style>
<body class="laytp-container">
<div id="opt_nav"></div>

<div class="layui-card" id="search-form">
    <div class="layui-card-body">
        <form class="layui-form" id="TableSearchFormId" lay-filter="TableSearchForm" onkeydown="keyTableSearch('TableSearchForm', 'datalist')">
            <div class="layui-form-item">
                <div class="layui-row">
                    <div class="layui-col-md3">
                        <label class="layui-form-label">所属单位</label>
                        <div class="layui-input-block">
                            <div id="chanid" class="xmselect_div">
                                <div class="xmselect_title">请选择</div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">人员性质</label>
                        <div class="layui-input-block">
                            <div id="person_nature" class="xmselect_div">
                                <div class="xmselect_title">请选择</div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">人员姓名</label>
                        <div class="layui-input-block">
                            <input type="text" name="person_name" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">证书名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" id="name" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">证书编号</label>
                        <div class="layui-input-block">
                            <input type="text" name="number" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">证书专业</label>
                        <div class="layui-input-block">
                            <input type="text" name="major" id="major" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">发证单位</label>
                        <div class="layui-input-block">
                            <input type="text" name="issue_unit" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">注册/发证日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="issue_dt" placeholder="请输入" class="layui-input bdate_sea_range_ymd" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">有效期止</label>
                        <div class="layui-input-block">
                            <input type="text" name="expiry_dt" placeholder="请输入" class="layui-input bdate_sea_range_ymd" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">证书形式</label>
                        <div class="layui-input-block">
                            <select name="form" id="form"></select>
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">证书状态</label>
                        <div class="layui-input-block">
                            <select name="state" id="state"></select>
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">电子件有效期</label>
                        <div class="layui-input-block">
                            <input type="text" name="electron_dt" placeholder="请输入" class="layui-input bdate_sea_range_ymd" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">下次年检时间</label>
                        <div class="layui-input-block">
                            <input type="text" name="inspect_dt" placeholder="请输入" class="layui-input bdate_sea_range_ymd" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">保管人</label>
                        <div class="layui-input-block">
                            <input type="text" name="custodianid" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">存放地</label>
                        <div class="layui-input-block">
                            <div id="store_addr" class="xmselect_div">
                                <div class="xmselect_title">请选择</div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">证书去向</label>
                        <div class="layui-input-block">
                            <select name="goes" id="goes"></select>
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">使用情况</label>
                        <div class="layui-input-block">
                            <select name="statueuse" id="statueuse"></select>
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">人员状态</label>
                        <div class="layui-input-block">
                            <select name="person_state" id="person_state">
                                <option value="">请选择</option>
                                <option value="在职">在职</option>
                                <option value="离职">离职</option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-col-md3">
                        <div class="layui-form-item search-div">
                            <div class="layui-form-item layui-inline">
                                <input type="hidden" id="type" name="type" value="">
                                <input type="hidden" id="personid" name="personid" value="">
                                <button class="laytp-btn laytp-btn-md laytp-btn-primary" id="TableSearchButton" type="button"><i class="layui-icon layui-icon-search"></i>查询</button>
                                <button class="layui-btn layui-btn-primary" onclick="listTableReset()" id="TableSearchReset" type="reset" ><i class="layui-icon layui-icon-refresh"></i>重置</button>
                                <div id="search_open" onclick="toggle_search()">
                                    <i class="layui-icon layui-icon-down"></i>展开
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>


<div class="layui-card" id="table-card">
    <div class="layui-card-body">
        <div class="layui-row">
            <?php include 'dao_fen.php' ?>
            <?php include 'dao_ren.php' ?>

            <div class="layui-col-md10" id="table_list">
                <div class="layui-card-body">
                    <table id="datalist" lay-filter="datalist"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="test-dropdown-toolbar-barDemo">
    <div class="tab-list-authbut">
        <a href="javascript:;" class="bar_opt" onclick="auth_but_func_show('查看','{{d.LAY_TABLE_INDEX}}')">查看</a>
    </div>
</script>
<script type="text/html" id="toolbarDemo">
    <div class = "layui-btn-container">
    </div>
</script>
<script>
    var currButAuth, currTabData;

    function qie_dao(type) {
        if(type == 'ren'){
            $(".dao_ren").removeClass('layui-hide');
            $(".dao_fen").addClass('layui-hide');
        }else{
            $(".dao_ren").addClass('layui-hide');
            $(".dao_fen").removeClass('layui-hide');
        }
    }


    var personid = getQueryVariable('personid') || '';
    var cert_name = decodeURI(getQueryVariable('cert_name') || '');
    if(cert_name){
        $("#name").val(cert_name);
    }

    layui.use(['laytp','tree','table','form','soulTable'], function () {
        var tree = layui.tree, table = layui.table, form = layui.form, soulTable = layui.soulTable;

        $('#TableSearchReset').click(function () {
            $('.xmselect_div>xm-select').find('.xm-label-block').css('display','none');
            $('.xmselect_div').append('<div class="xmselect_title">请选择</div>');
            searchTableFunc(form, table)
        });

        var height_l = $('.laytp-container').height() - 140;
        $('#tree_content').css('cssText','height:'+height_l+'px');
        $('.engindao_bac').css('cssText','height:'+height_l+'px');



        setSouTableExport('证件库');
        table.render({
            elem: "#datalist",id: "datalist"
            ,url: facade.url(ask_cert_list)
            ,where: {personid:personid,name:cert_name}
            ,page: true, height: 'full-140'
            ,soulSort: TabInit.soulSort,method: TabInit.method
            , toolbar: TabInit.toolbar, overflow: TabInit.overflow
            ,defaultToolbar: TabInit.defaultToolbar,filter: TabInit.filter
            ,request: TabInit.request,response: TabInit.response
            ,contextmenu:get_table_contextmenu(soulTable)
            ,text: TabInit.text
            ,parseData: function (res) {
                currButAuth = res.data.butauth;
                tableButShow(currButAuth);

                if(res.data.token_roletype == 1){
                    $("#rendaotit").removeClass('layui-hide')
                }


                var formArr = res.data.form;
                var form_str = '<option value="">请选择</option>';
                for(var i in formArr){
                    if(res.data.is_form == i){
                        form_str += '<option value="'+i+'" selected>'+formArr[i]+'</option>';
                    }else {
                        form_str += '<option value="'+i+'">'+formArr[i]+'</option>';
                    }
                }
                $('#form').html(form_str);

                var stateArr = res.data.state;
                var state_str = '<option value="">请选择</option>';
                for(var i in stateArr){
                    if(res.data.is_state == i){
                        state_str += '<option value="'+i+'" selected>'+stateArr[i]+'</option>';
                    }else{
                        state_str += '<option value="'+i+'">'+stateArr[i]+'</option>';
                    }
                }
                $('#state').html(state_str);

                var goesArr = res.data.goes;
                var goes_str = '<option value="">请选择</option>';
                for(var i in goesArr){
                    if(res.data.is_goes == i){
                        goes_str += '<option value="'+i+'" selected>'+goesArr[i]+'</option>';
                    }else{
                        goes_str += '<option value="'+i+'">'+goesArr[i]+'</option>';
                    }
                }
                $('#goes').html(goes_str);

                var statueuse = res.data.statueuse;
                var statueuse_str = '<option value="">请选择</option>';
                for(var i in statueuse){
                    if(res.data.is_statueuse == i){
                        statueuse_str += '<option value="'+i+'" selected>'+statueuse[i]+'</option>';
                    }else{
                        statueuse_str += '<option value="'+i+'">'+statueuse[i]+'</option>';
                    }
                }
                $('#statueuse').html(statueuse_str);

                xmselect_dan('chanid', res.data.chanid, res.data.is_chanid, function (res) {
                    setTimeout(function () {
                        searchTableFunc(form, table);
                    },100)
                })
                xmselect_dan('person_nature', res.data.nature, res.data.is_nature, function (res) {
                    setTimeout(function () {
                        searchTableFunc(form, table);
                    },100)
                })
                xmselect_dan('store_addr', res.data.store_addr, res.data.is_store_addr, function (res) {
                    setTimeout(function () {
                        searchTableFunc(form, table);
                    },100)
                })

                render_from();
                return {
                    "code": res.code,
                    "msg": res.message,
                    "count": res.data.data.total,
                    "data": res.data.data.data
                };
            }
            , cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{type:'numbers',title:'序号',fixed:'left'}
                ,{field: 'name', title: '证书名称',fixed:'left',width: 100,event:'name',templet:function (e) {
                    if(e.files.length === 0){
                        return '<span class="colorlan">'+e.name+'</span>';
                    }else{
                        return '<span class="colorlan">'+e.name+'</span>' + '&nbsp;&nbsp;<icon class="layui-icon layui-icon-link" title="有附件"></icon>';
                    }
                }}
                ,{field: 'person_name', title: '持证人',fixed:'left',minWidth: 100,event:'person_name', templet:function(e){
                    return '<span class="colorlan">'+e.person_name+'</span>';
                }}
                ,{field: 'person_nature', title: '人员性质',width: 100}
                ,{field: 'chanid_name', title: '所属单位',width: 100}
                ,{field: 'type', title: '证书分类',width: 100}
                ,{field: 'number', title: '证书编号',width: 100}
                ,{field: 'major', title: '证书专业',width: 100}
                ,{field: 'expiry_dt', title: '有效期止',width: 100}
                ,{field: 'issue_unit', title: '发证单位',width: 100}
                ,{field: 'issue_dt', title: '注册/发证日期',hide:true}
                ,{field: 'form_name', title: '证书形式',width: 100}
                ,{field: 'state_name', title: '证书状态',width: 100}
                ,{field: 'goes_name', title: '证书去向',width: 100}
                ,{field: 'statueuse_name', title: '使用情况',width: 100}
                ,{field: 'person_state', title: '人员状态',width: 100}
                ,{field: 'electron_dt', title: '电子件有效期',hide:true}
                ,{field: 'inspect_dt', title: '下次年检时间',hide:true}
                ,{field: 'store_addr', title: '存放地',width: 100}
                ,{field: 'custodian_name', title: '保管人',width: 100}
                ,{field: 'explain', title: '备注',hide:true}
                ,{fixed: 'right', title:'操作', toolbar: '#test-dropdown-toolbar-barDemo',align:'center',width:200}
            ]]
            , done: function (res) {
                soulTable.render(this);

                currTabData = res.data;
                $.each(currTabData, function(index,item){
                    var chk = $('tr[data-index=' + item.LAY_TABLE_INDEX + '] .tab-list-authbut');
                    for (var key in currButAuth) {
                        if(currButAuth[key].pagetype === 0 || currButAuth[key].pagetype === 1){
                            chk.append(' <a ' +
                                'href="javascript:;" ' +
                                'class="bar_opt layui-hide" ' +
                                'lay-event="search" ' +
                                'data-butname="'+currButAuth[key].butname+'" ' +
                                'data-title="'+currButAuth[key].title+'" ' +
                                'onclick="auth_but_func_'+currButAuth[key].butname+'(\''+currButAuth[key].title+'\', '+index+')"' +
                                '>'+currButAuth[key].title+'' +
                                '</a>');
                        }
                    }
                });
                show_tab_but(currTabData);

                // 处理列表fixed的高度问题
                $('div[lay-id="datalist"] .layui-table-main>table>tbody>tr').each(function (i) {
                    var height = $(this).height();
                    $('div[lay-id="datalist"] .layui-table-fixed-l>.layui-table-body>table>tbody>tr')
                        .eq(i).css('cssText','height:'+height+'px !important');
                    $('div[lay-id="datalist"] .layui-table-fixed-r>.layui-table-body>table>tbody>tr')
                        .eq(i).css('cssText','height:'+height+'px !important');
                });



            }
        });

        listTableSearch(form, table);


        table.on('tool(datalist)', function(obj){
            var data = obj.data;
            if(obj.event === 'person_name'){
                openPage('../cert_person/show.php?id='+data.personid);
            }
            if(obj.event === 'name'){
                openPage('../cert/show.php?id='+data.id);
            }
        });

    });


    function auth_but_func_show(buttitle, index){
        var trData = currTabData[index];
        openPage('show.php?id='+trData.id);
    }
    function auth_but_func_add(){
        openPageEdit('add.php?close=1');
    }
    function auth_but_func_edit(buttitle, index){
        var trData = currTabData[index];
        openPageEdit('edit.php?close=1&id='+trData.id);
    }
    function auth_but_func_delete(buttitle, index){
        var trData = currTabData[index];
        data_delete(ask_cert_del, {id:trData.id});
    }
    function auth_but_func_import(buttitle){
        openPage('../public/import.php?url='+ask_import_cert+'&down='+encodeURI('证件')+'&daolei=1', '770px', '490px');
    }
    function auth_but_func_muladd(){
        openPageEdit('muladd.php?close=1');
    }
    function auth_but_func_muledit(buttitle){
        var idArr = get_table_check_idarr();
        if(idArr.length < 1){
            facade.error(buttitle + "：请选择数据");return false;
        }
        openPageEdit('muledit.php?close=1&ids='+idArr.join(','));
    }
    function auth_but_func_muldel(buttitle){
        var idArr = get_table_check_idarr();
        if(idArr.length < 1){
            facade.error(buttitle + "：请选择数据");return false;
        }
        data_delete(ask_cert_del, {id: idArr.join(',')});
    }

    function opt_tree(data, status) {
        for (var i=0;i<data.length;i++){
            data[i]['spread'] = status;
            if(data[i].children != undefined){
                opt_tree(data[i].children, status);
            }
        }
        return data;
    }
</script>
</body>
</html>
